package at.fhj.itm10.ticketmaster.helper;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author Ballach md5 hashmaker from emailaddress
 * called by mailservive, insert md5 in registerbean 
 */
public class MD5HashmakerEmail {

	private static String md5code;

	public static String generateMD5Code(String recipient)
			throws NoSuchAlgorithmException {

		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(recipient.getBytes());

		byte byteData[] = md.digest();

		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < byteData.length; i++) {
			sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16)
					.substring(1));

		}

		System.out.println("MD5 : " + sb.toString());
		md5code = sb.toString();
		System.out.println(md5code);
		return md5code;

	}

	public static String getMd5code() {
		return md5code;
	}

	public static void setMd5code(String md5code) {
		MD5HashmakerEmail.md5code = md5code;
	}

}
